#include "sceneTreeWidget.h"
#include <QMessageBox>
#include "property.h"
#include "qtpropertymanager.h"
#include "qtvariantproperty.h"
#include "qttreepropertybrowser.h"

SceneTreeWidget::SceneTreeWidget(QWidget*parent/* =NULL */)
:QTreeWidget(parent)
{
	connect(this,SIGNAL(itemSelectionChanged()),this,SLOT(selChangedSlots()));
}

SceneTreeWidget::~SceneTreeWidget()
{

}

void SceneTreeWidget::contextMenuEvent(QContextMenuEvent *)
{
	
}

void SceneTreeWidget::selChangedSlots()
{
	QTreeWidgetItem* item=currentItem();
	if(item)
	{
		QVariant var = item->data(0,Qt::UserRole);
		BaseProperty* basepro = var.value<BaseProperty*>();
		mPropertyWidow->clear();
		mPropertyWidow->addProperty(basepro->mTopProperty);
	}
}

void SceneTreeWidget::propertyValueChanged(QtProperty *property, const QVariant &value)
{
	property->setModified(true);
	QTreeWidgetItem* item=currentItem();
	if(item)
	{
		QVariant var = item->data(0,Qt::UserRole);
		BaseProperty* basepro = var.value<BaseProperty*>();
		if(basepro->mType=="sceneManager_type")
		{
			((SceneManagerProperty*)basepro)->updateProperty();
		}
		else if(basepro->mType=="viewPort_type")
		{
			((ViewPortProperty*)basepro)->updateProperty();
		}
		else
		{

		}
	}
	property->setModified(false);
}